package com.h5lib.nchupfficeApp;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

import org.apache.http.conn.util.InetAddressUtils;

import android.util.Log;

/**
 * App Config
 * @author farmer
 *
 */
@SuppressWarnings("deprecation")
public class Config {
	
    public static final String DOMAIN = "http://" + Config.getLocalHostIp();
    public static final int PORT = 1990;
    public static final String WELCOME = "/login.html";
    
	/**
	 * 获取机器IP地址
	 * @return
	 */
	public static String getLocalHostIp()
    {
        String ipaddress = "127.0.0.1";
        try
        {
            Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
            while (en.hasMoreElements())
            {
                NetworkInterface networkInterface = en.nextElement();//得到每一个网络接口绑定的所有ip
                Enumeration<InetAddress> inet = networkInterface.getInetAddresses();
                while (inet.hasMoreElements())
                {
                    InetAddress ip = inet.nextElement();
                    if (!ip.isLoopbackAddress()  && InetAddressUtils.isIPv4Address(ip.getHostAddress()))
                    {
                    	Log.i("info", "IP:"+ip.getHostAddress());
                        return ipaddress = ip.getHostAddress();
                    }
                }

            }
        }
        catch (SocketException e)
        {
            Log.e("error", "获取本地ip地址失败");
            e.printStackTrace();
        }
        return ipaddress;
    }
    
	
}
